home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 14.9 KB | 469 lines | [TEXT/MPS ] |
- #
- # File: QuickTasks.vulib
- #
- # Contains: contains quick tasks for any scripts.
- #
- # Written by: David Gaxiola
- #
- # Copyright: © 1992 by Apple Computer, Inc., all rights reserved.
- #
- # Change History (most recent first):
- #
- # 8/19/92 DGG logging output made more readable
- # 8/10/92 DGG minor changes in variable names
- # 8/4/92 DGG "checkMethod" parameters removed.
- # 7/7/92 DGG comments added
- # 6/17/92 DGG creation
- #
- # To Do:
- #
-
- Libraries "Time.vulib";
-
- ### Logging Tasks
-
- (************************************************************************************
- * Task LogNormal(outputString, printTime)
- * Will send a given outputString as a comment to the output file, optionally
- * including the current time.
- ************************************************************************************)
- task LogNormal(outputString := "", printTime := false)
- begin
- if (printTime)
- print "# At ", GetCurrentTime(), " - ";
- if (not printTime)
- print "# ";
- println outputString;
- end;
-
- (************************************************************************************
- * Task LogError(errorString, printTime)
- * Will send a given errorString as a comment noted as being an error to the
- * output file, optionally including the current time.
- ************************************************************************************)
- task LogError(errorString := "", printTime := true)
- begin
- if (printTime)
- print "#-- Error at: ", GetCurrentTime(), " - ";
- if (not printTime)
- print "#-- Error: ";
- println errorString;
- end;
-
- (************************************************************************************
- * Task LogTime()
- * Will send the current time to the output file.
- ************************************************************************************)
- task LogTime()
- begin
- println "# The time is: ", GetCurrentTime();
- end;
-
- ### Counting tasks.
-
- (************************************************************************************
- * Task CountMenuItems(menuName)
- * Will count the number of menu items in a menu specified by name. If no menu
- * is specified, the total number of menu items in all of the menus is counted.
- * An integer is returned.
- ************************************************************************************)
- task CountMenuItems(menuName := undefined)
- begin
- if (not menuName)
- begin
- allMenus := collect [menu];
- runningTotal := 0;
- for each singleMenu in allMenus
- runningTotal := runningTotal + (card collect [menuItem m:singleMenu]);
- end;
- else
- runningTotal := (card collect [menuItem m:menuName]!);
- return runningTotal;
- end;
-
- (************************************************************************************
- * Task CountMenus()
- * Will count the number of menus in the current menubar. An integer is returned
- ************************************************************************************)
- task CountMenus()
- begin
- allMenus := collect [menu];
- return (card allMenus);
- end;
-
- (************************************************************************************
- * Task CountWindows()
- * Will count the number of windows currently visible to VU. An integer is
- * returned.
- ************************************************************************************)
- task CountWindows()
- begin
- allWindows := collect [window];
- return (card allWindows);
- end;
-
- (************************************************************************************
- * Task CountWindowItems(winName)
- * Will count the number of content items currently visible to VU in a given
- * window. The window is specified by title, otherwise the top windows is used
- * as default. An integer is returned.
- ************************************************************************************)
- task CountWindowItems(winName := undefined)
- begin
- if (not winName)
- match [window o:1 k:?items];
- else
- match [window t:winName k:?items];
- return (card items);
- end;
-
- ### "Getting" tasks.
-
- (************************************************************************************
- * Task GetMenuItemTitle(menuItemOrder, menuIdentifier)
- * Will return the title of a menu item specified by order in a menu spefiecied
- * either by order or title. menuItemOrder specifies the menu item's order in the
- * menu specified by menuIdentifier. It will return the title in the form of a
- * string.
- ************************************************************************************)
- task GetMenuItemTitle(menuItemOrder := 1, menuIdentifier := 1)
- begin
- if IsString(menuIdentifier)
- match [menuItem t:?menuTitle o:menuItemOrder m:[menu t:menuIdentifier]];
- else if IsInteger(menuIdentifier)
- match [menuItem t:?menuTitle o:menuItemOrder m:[menu o:menuIdentifier]];
- return menuTitle;
- end;
-
- (************************************************************************************
- * Task GetMenuTitle(menuOrder)
- * Will return the of a menu, given the menu's ordinality on the menubar. A
- * string is returned. Defaults to the Apple menu.
- ************************************************************************************)
- task GetMenuTitle(menuOrder := 1)
- begin
- match [menu t:?menuTitle o:menuOrder];
- return menuTitle;
- end;
-
- (************************************************************************************
- * Task GetTopWindow()
- * Will return the descriptor of the topmost window visible to VU.
- ************************************************************************************)
- task GetTopWindow()
- begin
- return match [window o:1];
- end;
-
- (************************************************************************************
- * Task GetWindowTitle(winOrder)
- * Will return the title of the window specified by its ordinality. The default is
- * the top window. A string is returned.
- ************************************************************************************)
- task GetWindowTitle(winOrder := 1)
- begin
- match [window t:?winTitle o:winOrder];
- return winTitle;
- end;
-
- ### Typing tasks.
-
- (************************************************************************************
- * Task TypeWithXXX(keylist := {})
- * All of the tasks beginning with "TypeWith" function in the same way. They are
- * passed a list of keys to type with the appropriate modifier key pressed at the
- * same time.
- ************************************************************************************)
- task TypeWithCommand(keylist := {})
- begin
- pressKey k:{commandKey};
- type k:keylist;
- releaseKey k:{commandKey};
- end;
-
- task TypeWithOption(keylist := {})
- begin
- println "blah!";
- pressKey k:{optionKey};
- type k:keylist;
- releaseKey k:{optionKey};
- end;
-
- task TypeWithControl(keylist := {})
- begin
- pressKey k:{controlKey};
- type k:keylist;
- releaseKey k:{controlKey};
- end;
-
- task TypeWithCommandOption(keylist := {})
- begin
- pressKey k:{commandKey, optionKey};
- type k:keylist;
- releaseKey k:{commandKey, optionKey};
- end;
-
- task TypeWithCommandControl(keylist := {})
- begin
- pressKey k:{commandKey, controlKey};
- type k:keylist;
- releaseKey k:{commandKey, controlKey};
- end;
-
- task TypeWithOptionControl(keylist := {})
- begin
- pressKey k:{optionKey, controlKey};
- type k:keylist;
- releaseKey k:{optionKey, controlKey};
- end;
-
- task TypeWithCommandOptionControl(keylist := {})
- begin
- pressKey k:{commandKey, optionKey, controlKey};
- type k:keylist;
- releaseKey k:{commandKey, optionKey, controlKey};
- end;
-
- ### Waiting tasks.
-
- (************************************************************************************
- * Task WaitForMatch( WhatToMatch, MaxWait := 60 )
- * This task will wait in a loop until a match for the descriptor provided
- * in WhatToMatch succeeds or MaxWait seconds have elapsed.
- * WhatToMatch is any descriptor.
- * MaxWait is the maximum number of seconds to wait.
- * If the match succeeds before MaxWait seconds, true is returned
- * If the match does not succeeds within MaxWait seconds, false is returned
- ************************************************************************************)
- task WaitForMatch( WhatToMatch, MaxWait := 60 )
- begin
- count := 0;
- while (not match WhatToMatch! ) and ( count <= maxWait )
- begin
- wait(1); # prevent too tight of a loop
- # prevents flooding the network
- count := count + 1;
- end;
-
- if ( count <= maxWait )
- return true;
- else
- return false;
- end;
-
- (************************************************************************************
- * Task WaitForNoMatch( WhatToMatch, MaxWait := 60 )
- * This task will wait in a loop until a match for the descriptor provided
- * in WhatToMatch fails or MaxWait seconds have elapsed.
- * WhatToMatch is any descriptor.
- * MaxWait is the maximum number of seconds to wait.
- * If the match fails before MaxWait seconds, true is returned
- * If the match does not fail within MaxWait seconds, false is returned
- ************************************************************************************)
- task WaitForNoMatch( WhatToMatch, MaxWait := 60 )
- begin
- count := 0;
- while ( match WhatToMatch! ) and ( count <= maxWait )
- begin
- wait(1); # prevent too tight of a loop
- # prevents flooding the network
- count := count + 1;
- end;
-
- if ( count <= maxWait )
- return true;
- else
- return false;
- end;
-
- ### "IS" tasks
-
- (************************************************************************************
- * Task IsXXX()
- * All of these tasks function in the same way. Each task is given an expression
- * which it will check if it evaluates to a particular type. If it does evaluate
- * then true is returned, otherwise, false is returned.
- ************************************************************************************)
- task IsDescriptor(expr)
- begin
- if typeOf(expr) = 'descriptor'
- return true;
- else
- return false;
- end;
-
- task IsInteger(expr)
- begin
- if typeOf(expr) = 'integer'
- return true;
- else
- return false;
- end;
-
- task IsList(expr)
- begin
- if typeOf(expr) = 'list'
- return true;
- else
- return false;
- end;
-
- task IsRegExpr(expr)
- begin
- if typeOf(expr) = 'regularExpression'
- return true;
- else
- return false;
- end;
-
- task IsString(expr)
- begin
- if typeOf(expr) = 'string'
- return true;
- else
- return false;
- end;
-
- task IsSymbol(expr)
- begin
- if typeOf(expr) = 'symbol'
- return true;
- else
- return false;
- end;
-
- ### Item checked/enabled tasks
-
- (************************************************************************************
- * Task XXXEnabled/Selected/Checked(descriptorTrait)
- * All of these tasks function in the same way. The tasks are given a descriptorTrait
- * specifying what to use as a base for the match operation. The descriptorTrait is
- * either a string or an integer, depending on the type of the descriptorTrait.
- * These tasks will "intelligently" tell the difference between a string and an
- * integer and take the appropriate action. The task will return a boolean
- * depending logically on whether the object is enabled, selected, or checked.
- ************************************************************************************)
- task ButtonEnabled(descriptorTrait := "")
- begin
- if IsString(descriptorTrait)
- match [button t:descriptorTrait e:?buttonEnabledState w:[window o:1]];
- else if IsInteger(descriptorTrait)
- match [button o:descriptorTrait e:?buttonEnabledState w:[window o:1]];
- return buttonEnabledState;
- end;
-
- task CheckBoxEnabled(descriptorTrait := "")
- begin
- if IsString(descriptorTrait)
- match [checkBox t:descriptorTrait e:?boxEnabledState w:[window o:1]];
- else if IsInteger(descriptorTrait)
- match [checkBox o:descriptorTrait e:?boxEnabledState w:[window o:1]];
- return boxEnabledState;
-
- end;
-
- task MenuEnabled(descriptorTrait := "")
- begin
- if IsString(descriptorTrait)
- match [menu t:descriptorTrait e:?menuEnabledState];
- else if IsInteger(descriptorTrait)
- match [menu o:descriptorTrait e:?menuEnabledState];
- return menuEnabledState;
- end;
-
- task MenuItemEnabled(descriptorTrait := "")
- begin
- if IsString(descriptorTrait)
- match [menuItem t:descriptorTrait e:?menuItemEnabledState];
- else if IsInteger(descriptorTrait)
- match [menuItem o:descriptorTrait e:?menuItemEnabledState];
- return menuItemEnabledState;
- end;
-
- task CheckBoxChecked(descriptorTrait := "")
- begin
- if IsString(descriptorTrait)
- match [checkBox t:descriptorTrait s:?buttonStyle w:[window o:1]];
- else if IsInteger(descriptorTrait)
- match [checkBox o:descriptorTrait s:?buttonStyle w:[window o:1]];
- if (buttonStyle[1] = 1)
- buttonSelected := true;
- else
- buttonSelected := false;
- return buttonSelected;
- end;
-
- task RadioButtonSelected(descriptorTrait := "")
- begin
- if IsString(descriptorTrait)
- match [radioButton t:descriptorTrait s:?buttonStyle w:[window o:1]];
- else if IsInteger(descriptorTrait)
- match [radioButton o:descriptorTrait s:?buttonStyle w:[window o:1]];
- if (buttonStyle[1] = 1)
- buttonSelected := true;
- else
- buttonSelected := false;
- return buttonSelected;
- end;
-
- ### SelectionTasks
-
- (************************************************************************************
- * Task SelectRectangle(theRectangle)
- * This task is given the bounding rectangle of the object that is to be selected.
- * SelectUnsupported will then move to the center of the rectangle and click on it.
- * Nothing is returned.
- ************************************************************************************)
- task SelectRectangle(theRectangle := {0, 0, 1, 1})
- begin
- xAvg := (theRectangle[1] + theRectangle[3]) / 2;
- yAvg := (theRectangle[2] + theRectangle[4]) / 2;
- move a:{xAvg, yAvg};
- click;
- end;
-
- (************************************************************************************
- * Task DoCheckBox(descriptorTrait)
- * This task takes descriptorTraits in the same manner as the XXXEnabled tasks do.
- * Given a descriptorTrait this task will ensure that the specified checkBox
- * is checked.
- ************************************************************************************)
- task DoCheckBox(descriptorTrait := "")
- begin
- if (not CheckBoxChecked(descriptorTrait))
- if IsString(descriptorTrait)
- select [checkBox t:descriptorTrait w:[window o:1]];
- else if IsInteger(descriptorTrait)
- select [checkBox o:descriptorTrait w:[window o:1]];
- end;
-
- (************************************************************************************
- * Task UnCheckBox(descriptorTrait)
- * This task takes descriptorTraits in the same manner as the XXXEnabled tasks do.
- * Given a descriptorTrait, this task will ensure that the specified checkBox is
- * not checked.
- ************************************************************************************)
- task UnCheckBox(descriptorTrait := "")
- begin
- if CheckBoxChecked(descriptorTrait)
- if IsString(descriptorTrait)
- select [checkBox t:descriptorTrait w:[window o:1]];
- else if IsInteger(descriptorTrait)
- select [checkBox o:descriptorTrait w:[window o:1]];
- end;
-
- (************************************************************************************
- * Task DoSelectRadioButton(descriptorTrait)
- * This task takes descriptorTraits in the same manner as the XXXEnabled tasks do.
- * Given a descriptorTrait, this task will ensure that the specified checkBox is
- * checked.
- ************************************************************************************)
- task DoSelectRadioButton(descriptorTrait := "")
- begin
- if (not RadioButtonSelected(descriptorTrait))
- if IsString(descriptorTrait)
- select [radioButton t:descriptorTrait w:[window o:1]];
- else if IsInteger(descriptorTrait)
- select [radioButton o:descriptorTrait w:[window o:1]];
- end;
-